package com.sgzn.sgpay.web.handle;

import com.sgzn.sgpay.enums.AppName;
import com.sgzn.sgpay.model.request.SgsBaseRequest;
import com.sgzn.sgpay.model.request.SgsMerchantBaseRequest;
import com.sgzn.sgpay.model.request.SgsUserBaseRequest;
import com.sgzn.sgpay.web.request.Impl.MerchantBaseRequest;
import com.sgzn.sgpay.web.request.Impl.UserBaseRequest;
import com.sgzn.sgpay.web.request.Request;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 组装service请求处理器
 * @author huangsenguang
 * @version Id: AssembleSgsRequestHandle.java, v 0.1 2018/4/8 22:50 huangsenguang Exp $$
 */
@Component
public class AssembleCommonHandle {

    /**
     * 组装公共请求信息
     * @param sourceRequest
     * @param targetRequest
     */
    public  void assemble(Request sourceRequest, SgsBaseRequest targetRequest){
        targetRequest.setInitiationID(sourceRequest.getInitiationID());
        targetRequest.setReqTime(new Date());
        targetRequest.setLoginChannel(AppName.SGW.getNumber());
    }

    /**
     * 组装用户公共请求信息
     * @param sourceRequest
     * @param targetRequest
     */
    public  void assembleUserRequest(UserBaseRequest sourceRequest, SgsUserBaseRequest targetRequest){
        targetRequest.setInitiationID(sourceRequest.getInitiationID());
        targetRequest.setReqTime(new Date());
        targetRequest.setLoginChannel(AppName.SGW.getNumber());
        targetRequest.setUserId(sourceRequest.getUserId());
        targetRequest.setOpenId(sourceRequest.getOpenId());
    }

    /**
     * 组装商户公共请求信息
     * @param sourceRequest
     * @param targetRequest
     */
    public  void assemble(MerchantBaseRequest sourceRequest, SgsMerchantBaseRequest targetRequest){
        targetRequest.setInitiationID(sourceRequest.getInitiationID());
        targetRequest.setReqTime(new Date());
        targetRequest.setLoginChannel(AppName.SGW.getNumber());
        targetRequest.setMchId(sourceRequest.getMchId());
    }
}

